package com.jeeplus.modules.anny.order.web;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.modules.anny.order.entity.AnnyOrder;
import com.jeeplus.modules.anny.order.service.AnnyOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping(value = "${adminPath}/order/annyOrder")
public class OrderCollectionController {
    AjaxJson j = new AjaxJson();

    @Autowired
    private AnnyOrderService annyOrderService;


    /**
     * 待付款
     */
    @ResponseBody
    @RequestMapping(value = "pendingpay")///order/annyOrder
    public AjaxJson pendingpay(RedirectAttributes redirectAttributes, HttpServletRequest request) {
        //拿到用户id
        //String userid = WeiXinUserInfo.getWxUserid(request);

        //用户ID
        List<AnnyOrder> order = annyOrderService.Pendingpay("1");
        //返回所有未支付订单 0 未支付  1支付

        if (order.size() == 0) {//没有未支付的订单
            j.setMsg("没有可支付的订单");
        }

        //返回所有未支付订单
        j.setMsg(order.toString());

        return j;
    }


    /**
     * 待发货
     */
    @ResponseBody
    @RequestMapping(value = "pendingdelivery")///order/annyOrder
    public AjaxJson pendingdelivery(RedirectAttributes redirectAttributes, HttpServletRequest request) {
        //拿到用户id
        //String userid = WeiXinUserInfo.getWxUserid(request);

        //用户ID
        List<AnnyOrder> order = annyOrderService.Pendingpay("1");
        //返回所有未支付订单 0 未发货  1已发货

        if (order.size() == 0) {//没有未发货的订单
            j.setMsg("没有未发货订单");
        }

        //返回所有待发货订单
        j.setMsg(order.toString());

        return j;
    }

    /**
     * 待收货
     */
    @ResponseBody
    @RequestMapping(value = "goodstobereceived")///order/annyOrder
    public AjaxJson Goodstobereceived(RedirectAttributes redirectAttributes, HttpServletRequest request) {
        //拿到用户id
        //String userid = WeiXinUserInfo.getWxUserid(request);

        //用户ID
        List<AnnyOrder> order = annyOrderService.Goodstobereceived("1");

        if (order.size() == 0) {//没有未发货的订单
            j.setMsg("没有未收货订单");
        }

        //返回所有待发货订单
        j.setMsg(order.toString());

        return j;
    }

    /**
     * 已完成
     */
    @ResponseBody
    @RequestMapping(value = "completed")///order/annyOrder
    public AjaxJson completed(RedirectAttributes redirectAttributes, HttpServletRequest request) {
        //拿到用户id
        //String userid = WeiXinUserInfo.getWxUserid(request);

        //用户ID
        List<AnnyOrder> order = annyOrderService.Goodstobereceived("1");

        if (order.size() == 0) {//没有未发货的订单
            j.setMsg("没有已完成 订单");
        }

        //返回所有待发货订单
        j.setMsg(order.toString());

        return j;
    }


}